package com.lagou.article.controller;

import com.lagou.article.entity.Article;
import com.lagou.article.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @program: article
 * @author: GYL
 * @create: 2020-09-29 14:33
 * @description: 博客展示页面
 */
@Controller
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    ArticleService articleService;
    @RequestMapping(value = "/homePage")
    public String homePage(Model model,Integer currentPage,Integer pageSize){
        if(currentPage==null||currentPage<0){
            currentPage=0;
        }
        if(pageSize==null||pageSize<0){
            pageSize=2;
        }
        Page page = articleService.list(currentPage,pageSize);
        model.addAttribute("articles",page.getContent());
        model.addAttribute("currentPage",page.getPageable().getPageNumber());
        model.addAttribute("pageSize",page.getPageable().getPageSize());
        model.addAttribute("totalPage",page.getTotalPages());
        return "index";
}
}